import { connect } from 'react-redux'

import ProductList from '../components/ProductList'
import { getProducts, addToCart } from '../actions'

const mapStateToProps = (state, ownProps) => {
  return {
    products: state.products.data
  }
}

const mapDispatchToProps = (dispatch, ownProps) => {
  return {
    getProducts: (page) => {
      dispatch(getProducts(page))
    },
    addToCart: (product) => {
      dispatch(addToCart(product))
    }
  }
}

export default connect(mapStateToProps, mapDispatchToProps)(ProductList)
